package trabajoISW2.presentation.shared;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import trabajoISW2.domain.implementations.Author;
import trabajoISW2.domain.implementations.Book;

public class AuthorMapper {


	public static AuthorDTO createDTO(Author au){
		AuthorDTO dto = new AuthorDTO(au.getAuthorId(), au.getName(), au.getSurname());
		Iterator<Book> it = au.getBooks().iterator();
		BookDTO bdto;
		Book b;
		while (it.hasNext()){
			b= it.next();
			bdto = BookMapper.createDTO(b);
			dto.getBooks().add(bdto);
		}
		return dto;
	}
	
	public static Author updateDomainObject (AuthorDTO dto){

		Author au = new Author(dto.getAuthorId(), dto.getName(), dto.getSurname());
		Iterator<BookDTO> it = dto.getBooks().iterator();
		BookDTO bdto;
		Book b;
		while (it.hasNext()){
			bdto= it.next();
			b = BookMapper.updateDomainObject(bdto);
			au.addBook(b);
		}
		return au;
			
	}
}
